
(function($){

Core.ObjectTypes["#mgm"] = function(){
	$('#mgm_tabs').find(">div:eq(0)").accordion({fillSpace: true,collapsible:true})
					.bind("accordionchange",
						function(e,ui){
							var id=ui.newHeader.find("input[type=hidden]:eq(0)").val();
							if ( id ){
								ui.newContent.one("update_tab", function(e,d,er,h){ $(this).html( h ); } );
								ui.newContent.jsonRequest(id,{action:"draw"},"update_tab");
							}
						});

	$("#mgm_tabs").dialog({autoOpen: false,
							modal:true,
							width:600,
							resize: function(){$('#mgm_tabs').find(">div:eq(0)").accordion("resize")}
						});

	$(this).button({icons:{primary:"ui-icon-wrench"},text:false})
			.bind("click", function(){
								$('#mgm_tabs').dialog("open");
							});
};

Core.Callbacks["mgmReload"] = function(e,data,err,html){
	if ( !err ){
		var ac = $('#mgm_tabs').find(">div:eq(0)"),
			od = ac.accordion("option", "active");
		ac.accordion("activate", false);
		ac.accordion("option","active", od);
	}
};

}(jQuery));